package com.rxt.controller;


import com.rxt.common.result.Result;
import com.rxt.model.vo.KKonwledgePageVo;
import com.rxt.model.vo.KKonwledgeVo;
import com.rxt.service.IKKonwledgeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Api(tags = "知识模块")
@Slf4j
@RestController
@RequestMapping("/kKonwledge")
public class KKonwledgeController {

    @Autowired
    private IKKonwledgeService ikKonwledgeService;

    @GetMapping
    //加上此注解代表要对此接口记录日志
    @ApiOperation("分页获取知识列表")
    public Result page(KKonwledgePageVo kKonwledgeVo){
        return ikKonwledgeService.getPage(kKonwledgeVo);
    }

    @PostMapping("/publish")
    @ApiOperation("发布知识")
    public Result publish(@RequestBody KKonwledgeVo kKonwledgeVo){

        return ikKonwledgeService.publish(kKonwledgeVo);
    }

    @GetMapping("/hot")
    @ApiOperation("热门知识")
    public Result hot(){

        return ikKonwledgeService.hot();
    }

    /**
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询单个知识，包含评论信息")
    public Result getOne(@PathVariable Long id){

        return ikKonwledgeService.getOneByID(id);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("根据id删除单个知识")
    public Result delete(@PathVariable Long id){

        return ikKonwledgeService.delete(id);
    }

    @GetMapping("/users")
    @ApiOperation("查找用户发布的文章")
    public Result users(){

        return ikKonwledgeService.users();
    }
}

